package com.feidee.bigdata.controller;

import com.alibaba.fastjson.JSON;
import com.feidee.bigdata.model.CommonResponse;
import com.feidee.bigdata.model.Payment;
import com.feidee.bigdata.PaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;


/**
 * Created by Admin on 2020/4/7.
 */
@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;
    @Value("${service.port}")
    private String SERVER_PORT;

    private Logger logger = LoggerFactory.getLogger(PaymentController.class);

    @RequestMapping("/insert")
    @ResponseBody
    public CommonResponse insert(@RequestBody Payment payment) {
        logger.info("本次insert接口请求参数为：" + JSON.toJSONString(payment));
        int insert = paymentService.insert(payment);
        if (insert > 0) {
            return new CommonResponse(200, "数据插入成功,插入主机端口号：" + SERVER_PORT, insert);
        } else {
            return new CommonResponse(-1, "数据插入失败", null);
        }
    }

    @RequestMapping("/select/{id}")
    @ResponseBody
    public CommonResponse select(@PathVariable Long id) {
        logger.info("本次select接口请求id为：" + id);
        Payment result = paymentService.select(id);
        if (result == null) {
            return new CommonResponse(-1, "数据查询失败，查询ID：" + id, null);
        } else {
            return new CommonResponse(200, "数据查询成功,查询主机端口号：" + SERVER_PORT, result);
        }
    }

    @RequestMapping("/zipkin")
    public String zipkin() {
        return "hi,i am zipkin";
    }

}
